
import 'dart:convert';
import 'dart:async';
import 'package:flutter_trip/model/home_model.dart';
import 'package:flutter_trip/model/search_model.dart';
import 'package:http/http.dart' as http;

///首页大接口
class SearchDao{
  static Future<SearchModel> fetch(String url , String text) async{
    var uri = Uri.parse(url);
    final response =await http.get(uri);
    if(response.statusCode == 200){
      Utf8Decoder utf8decoder = Utf8Decoder();//修复中文乱码问题
      var result = json.decode(utf8decoder.convert(response.bodyBytes));
      //只有当前输入的内容和服务端返回的内容一致时才渲染
      SearchModel model= SearchModel.fromJson(result);
      model.keyword = text;
      return model;
    }else{
      throw Exception("加载HomeJson失败");

    }
  }
}